<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新建元素</title>
    <script src="../../js/jquery-1.4.2.js"></script>
</head>
<body>
    <button id="b1">新建元素</button>
    <button id="b2">删除元素</button>
</body>
    <script>
        //新建
        var r = Math.floor(Math.random()*255)
        var g = Math.floor(Math.random()*255)
        var b = Math.floor(Math.random()*255)
        $(function (){
            //删除
            $("#b2").click(function (){
                $("body>div:first").remove()
            })

            //新建
            $("#b1").click(function (){
                $("body").append($("<div style='width: 100px;height: 100px;border: 1px solid #000;background: rgb("+r+","+g+","+b+")'></div>"))
            })
        })
    </script>
</html>